package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsMpSlideshowParam;
import com.macro.mall.dto.BmsPromotionalImgParam;
import com.macro.mall.model.BmsMpSlideshow;
import com.macro.mall.model.BmsPromotionalImg;
import com.macro.mall.service.BmsMpSlideshowService;
import com.macro.mall.service.BmsPromotionalImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宣传图像管理Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsPromotionalImgController")
@Tag(name = "BmsPromotionalImgController", description = "宣传图像管理")
@RequestMapping("/promotionalImg")
public class BmsPromotionalImgController {
    @Autowired
    private BmsPromotionalImgService bmsPromotionalImgService;

    @ApiOperation("添加宣传图")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody BmsPromotionalImgParam bmsPromotionalImgParam) {
        int count = bmsPromotionalImgService.create(bmsPromotionalImgParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改宣传图")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@RequestBody BmsPromotionalImgParam bmsPromotionalImgParam) {
        int count = bmsPromotionalImgService.update(bmsPromotionalImgParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("分页查询宣传图")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsPromotionalImg>> getList(@RequestBody BmsPromotionalImgParam bmsPromotionalImgParam) {
        List<BmsPromotionalImg> bmsPromotionalImgList = bmsPromotionalImgService.getList(bmsPromotionalImgParam);
        return CommonResult.success(CommonPage.restPage(bmsPromotionalImgList));
    }

    @ApiOperation("根据id获取宣传图信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsPromotionalImg> getItem(@PathVariable Long id) {
        BmsPromotionalImg bmsPromotionalImg = bmsPromotionalImgService.getItem(id);
        return CommonResult.success(bmsPromotionalImg);
    }

    @ApiOperation("删除宣传图")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
        int count = bmsPromotionalImgService.delete(ids);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改显示状态")
    @RequestMapping(value = "/update/showStatus", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateShowStatus(@RequestBody BmsPromotionalImgParam bmsPromotionalImgParam) {
        int count = bmsPromotionalImgService.updateShowStatus(bmsPromotionalImgParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("小程序查询宣传图")
    @RequestMapping(value = "/mp/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<BmsPromotionalImg>> getMpList() {
        List<BmsPromotionalImg> bmsMpSlideshowList = bmsPromotionalImgService.getMpList();
        return CommonResult.success(CommonPage.restPage(bmsMpSlideshowList));
    }
}
